package io.github.jyrmc.deploy.task

import io.github.jyrmc.deploy.utils.CommandLineUtils
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction

/**
 * ssh支持的task
 *
 * @author jyRMc
 * @since 2024/9/14 16:44
 **/
open class SshTask : DefaultTask() {
    @Input
    @Optional
    lateinit var host: String

    @Input
    var port: Int = 22

    @Input
    var username: String = "root"

    @Input
    @Optional
    lateinit var password: String

    @Input
    lateinit var commandLine: String


    @TaskAction
    fun sshAction() {
        val result = CommandLineUtils.exec(host, port, username, password, commandLine)
        println(result)
    }
}